﻿using System;
using System.Text.RegularExpressions;

namespace RailwayReservationWeb
{
    public class Formatting
    {
        public static string GetNumbers(string s)
        {
            // if (s.Trim().Length == 0) return String.Empty;
            return Regex.Replace(s, @"\D", String.Empty);
        }

        public static decimal? ToDecimal(string s)
        {
            try
            {
                return Convert.ToDecimal(GetNumbers(s));
            }
            catch (Exception)
            {
                return null;
            }
        }

        public static DateTime? ToDateTime(string s)
        {
            try
            {
                return Convert.ToDateTime(s);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public static string PhoneNumber(decimal phone)
        {
            return String.Format("{0:### ### ####}", phone);
        }

        public static string SSIDNumber(decimal phone)
        {
            return String.Format("{0:### ### ### ###}", phone);
        }

        public static string RequestStatus(object code)
        {
            short _code = Convert.ToInt16(code);
            switch (_code)
            {
                case 0: return "New Request";
                case 1: return "Processing";
                case -1: return "Rejected";
                case 2: return "Processed";
                default: return String.Empty;
            }
        }
    }
}